import java.util.Calendar;

//作业4-Person-oldest
class MyDate {
    private int year, month, day;
    private static int thisYear = java.util.Calendar.getInstance().get(Calendar.YEAR);

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public static int getThisYear() {
        return MyDate.thisYear;
    }

    public int getYear() {
        return this.year;
    }

    public String toString() {
        return this.year + "年" + this.month + "月" + this.day + "日";
    }
}

public class Person {
    private String name;
    private MyDate birthdate;

    public Person(String name, MyDate birthdate) {
        this.name = name == null ? "" : name;
        this.birthdate = birthdate;
    }

    public int getAge(int year) {
        return year - this.birthdate.getYear();
    }

    public int getAge() {
        return getAge(MyDate.getThisYear());
    }

    public int older(Person per) {
        return per.birthdate.getYear() - this.birthdate.getYear();
    }

    /*
     * 以下补充方法
     * public static Person oldest(Person[] pers)
     * 说明：返回pers对象数组元素的年龄最大者，
     * 必须且仅能调用older方法进行年龄比较
     */
    public static Person oldest(Person[] pers) {
        if (pers.length == 1)
            return pers[0];
        Person oldestPer = pers[0];
        for (int i = 1; i < pers.length; i++) {
            oldestPer = pers[i].older(oldestPer) < 0 ? oldestPer : pers[i];
        }
        return oldestPer;
    }

    public String toString() {
        return this.name + "," + (this.birthdate == null ? "" : birthdate.toString());
    }

    public static void main(String[] args) {
        Person[] pers = { new Person("李小明", new MyDate(1994, 3, 15)), new Person("张莉", new MyDate(1998, 4, 5)),
                new Person("朱红", new MyDate(1995, 3, 12)) };
        System.out.println(pers[0].toString() + "  今年 " + (pers[0].getAge()) + "岁");
        System.out.println(Person.oldest(pers));
    }
}
/*
 * 测试用例说明：
 * 输入：无
 * 输出：
 * 李小明,1994年3月15日 今年 30岁
 * 李小明,1994年3月15日
 */